package com.linkgap.cloud.influx;

import com.influxdb.client.InfluxDBClient;
import com.influxdb.client.InfluxDBClientFactory;
import com.influxdb.client.WriteApiBlocking;
import com.influxdb.client.domain.WritePrecision;
import com.influxdb.client.write.Point;

import java.time.Instant;

public class InfluxDB2Example {


    public static void main(final String[] args) {

        // You can generate an API token from the "API Tokens Tab" in the UI
        String token = "nuD3r_nlXiqcab5Vbo-fY58IpXnLY_L4sUGyZBYtsrEl9j1JfXouLIiM94b8G2QVy3uvjaWxi1ba6qsIhks-jg==";
        String bucket = "iot";
        String org = "linkgap";

        InfluxDBClient client = InfluxDBClientFactory.create("http://192.168.47.128:8086", token.toCharArray());


        //一个租户一张measurement
        String tenantId = "linkgap";


        Point point = Point
                .measurement("mem")
                .addTag("host", "host1")
                .addField("used_percent", 23.43234543)
                .time(Instant.now(), WritePrecision.NS);

        WriteApiBlocking writeApi = client.getWriteApiBlocking();
        writeApi.writePoint(bucket, org, point);

        client.close();

    }




}
